import java.util.Stack;

public class Solution {
    public int[] reversePrint(ListNode head) {
        //利用单调栈，先遍历链表将值放入栈
        //再出栈放入数组
        Stack<Integer> stack=new Stack<>();
        if(head==null){
            return new int[0];
        }

        ListNode cur=head;
        int count=0;
        while(cur!=null){
            count++;
            stack.push(cur.val);
            cur=cur.next;
        }
        int i=0;
        int[] arr=new int[count];
        while(!stack.isEmpty()){
            arr[i++]=stack.pop();

        }
        return arr;


    }
}